#include "PrecompiledHeaders.h"
#include "Game.h"
#include "SingleUserPlayState.h"
#include "ReplayState.h"
#include "MenuMain.h"
#include "MenuOptions.h"
#include "MenuLevelSelect.h"
#include "QuickPlayManager.h"
#include "StoryModeManager.h"
#include "MenuHighScores.h"
#include "MenuInGame.h"
#include "MenuCredits.h"
#include "ReplayManager.h"

Game::Game(bool pod_control, bool pod_config_file)
{
    // Create game resources and the state manager
	game_resources = new GameResources(pod_control, pod_config_file);
	state_manager = new GameStateManager(game_resources);
	SingleUserPlayState *sups = new SingleUserPlayState();
    QuickPlayManager *qpm = new QuickPlayManager();
    StoryModeManager *smm = new StoryModeManager();
    MenuInGame *mig = new MenuInGame();
    MenuMain *mm = new MenuMain();
    MenuHighScores *mhs = new MenuHighScores();
    ReplayManager *rm = new ReplayManager();
    
	// Add all of the game states
	state_manager->addGameState("single_user_play", sups);
    state_manager->addGameState("replay",           new ReplayState);
	state_manager->addGameState("menu",             mm);
	state_manager->addGameState("in_game_menu",     (MenuState *)mig);
	state_manager->addGameState("high_scores_menu", mhs);
	state_manager->addGameState("options",          new MenuOptions);
    state_manager->addGameState("level_select",     new MenuLevelSelect);
	state_manager->addGameState("quick_play_menu",  qpm);
    state_manager->addGameState("story_mode_menu",  smm);
    state_manager->addGameState("replay_manager",   rm);
    state_manager->addGameState("credits",          new MenuCredits);
    
    // Nasty pointer stuff
    qpm->getStatePointers();
    smm->getStatePointers();
    sups->getStatePointers();
    mig->getStatePointers();
    mm->getStatePointers();
    mhs->getStatePointers();
    rm->getStatePointers();
    
    qpm->getResourcesPointer(game_resources);
    smm->getResourcesPointer(game_resources);
}

Game::~Game()
{
    delete state_manager;
	delete game_resources;
}

void Game::start()
{
    state_manager->start(state_manager->findByName("menu"));
}

